package com.ewhl.mark.nss.net;

import android.content.Context;

import com.ewhl.mark.nss.MapBean;
import com.ewhl.mark.nss.volley.MyErrorListener;
import com.ewhl.mark.nss.volley.MyReponseListener;
import com.ewhl.mark.nss.volley.VolleyRequest;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2016/9/7.
 */
public class NetValues extends VolleyRequest {

    private static NetValues netValues;

    public NetValues(Context ctx) {
        super(ctx);
    }

    public static NetValues getInstance(Context contex) {
        if (netValues == null) {
            netValues = new NetValues(contex);
        }
        return netValues;
    }

    private final static String ROOT_PATH = "http://www.nongshengsheng.com/index.php/Api/";

    private final static String USER_URL = ROOT_PATH + "User/";
    private final static String MAP_URL =ROOT_PATH + "Api/";
    private final static String API_URL = ROOT_PATH + "api/";
    /**
     * 获取注册时短信验证码
     * @param mobile   scene 1 注册 2 修改密码  6 绑定手机号  3注册
     * @param callBack
     */
    public  void  send_sms(String mobile , String scene,MyReponseListener callBack, MyErrorListener errorListener) {
        Map<String, Object> map = new HashMap<>();
        map.put("mobile", mobile);
        map.put("scene", scene);
        VolleyGet(API_URL+"send_validate_code", map, OptionBean.class,callBack,errorListener);
    }

    public void user_third_reg(String nickname, String head_pic,String mobile,int sex ,String openid,String oauth,  String coed,MyReponseListener myReponseListener,MyErrorListener errorListener) {
        Map<String, String> map = new HashMap<>();
        map.put("mobile", mobile);
        map.put("head_pic", head_pic);
        map.put("nickname", nickname);
        map.put("sex", sex+"");
        map.put("code", coed);
        map.put("openid", openid);
        map.put("oauth", oauth);

        VolleyPost(API_URL+"third_reg", map, LoginBean.class,myReponseListener,errorListener);
    }
    public  void get_user_info(String uid,int role,int type,String token, MyReponseListener callBack, MyErrorListener errorListener ){
        Map<String, Object> map = new HashMap<>();
        map.put("user_id", uid);
        map.put("role",role);
        map.put("type",type);
        map.put("token",token);
        if(type==1){
            VolleyGet(MAP_URL+"get_user_info", map, UserInfo.class,callBack,errorListener);
        }else {
            VolleyGet(MAP_URL+"get_user_info", map, UserInfob.class,callBack,errorListener);
        }

    }
    /**
     * 登陆
     * @param mobile
     * @param password
     * @param callBack
     */
    public void login( String mobile,String password,  MyReponseListener callBack, MyErrorListener errorListener) {
        Map<String, Object> map = new HashMap<>();
        map.put("mobile", mobile);
        map.put("password",password);
        VolleyGet(USER_URL+"login", map, LoginBean.class,callBack,errorListener);
    }

    public void check_key(String key, MyReponseListener callBack, MyErrorListener errorListener) {
        Map<String, Object> map = new HashMap<>();
        map.put("key", key);
        VolleyGet(USER_URL+"check_key", map, OptionBean.class,callBack,errorListener);
    }

    /**
     * 三方验证登录
     * @param openid
     * @param type
     * @param callBack
     * @param errorListener
     */
    public void checkReg(String openid,String type, MyReponseListener callBack, MyErrorListener errorListener) {
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("openid", openid);
        map.put("type", type);
        VolleyPost(USER_URL+"check_login", map, LoginBean.class, callBack,errorListener);
    }

    public void get_near_list(int  type,String ne, String sw, MyReponseListener callBack, MyErrorListener errorListener) {
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("type", type+"");
        map.put("ne", ne);
        map.put("sw", sw);
        VolleyPost(USER_URL+"map_list", map, MapBean.class, callBack,errorListener);
    }

    /**
     * https://api.weixin.qq.com/sns/oauth2/access_token?appid= APPID&secret=SECRET&code=CODE&grant_type=authorization_code
     * @param code
     * @param callBack
     * @param errorListener
     */
    public void getwx_OpenID(String code,MyReponseListener callBack,MyErrorListener errorListener){
        Map<String, String> map = new HashMap<>();
        map.put("appid", "wx52ec5d2e46b5ad8d");
        map.put("secret", "5871d1f79fa372f667ebca50d842313e");
        map.put("grant_type", "authorization_code");
        map.put("code", code);
        VolleyPost("https://api.weixin.qq.com/sns/oauth2/access_token", map, WxInfo.class,callBack,errorListener);
    }

    public void getWx_info(String access_token, String openid,MyReponseListener callBack,MyErrorListener errorListener) {
        // TODO Auto-generated method stub
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("access_token", access_token);
        map.put("openid", openid);
        VolleyPost("https://api.weixin.qq.com/sns/userinfo", map, WxUserInfo.class, callBack,errorListener);
    }
}



